// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
const tool = require('ToolUtil');
cc.Class({
    extends: cc.Component,
    properties: {
        playerName: cc.Label,
        playerGold: cc.Label,
        tableLayer: cc.Node,
        head: cc.Sprite,
        _playerHead: null,
        btnShop:cc.Button
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },



    init: function () {
        if (tool.PlayerManager().m_MySelf) {
            var mySelf = tool.PlayerManager().m_MySelf;
            this.playerName.string = mySelf.m_showName;
            this.playerGold.string = mySelf.m_silver;
            if (this.head.getComponent('WebImage')) {
                this.head.getComponent('WebImage').initWithFileUrl(mySelf.m_headUrl, mySelf.m_btSex, mySelf.m_dbid);
            }
        }
    },

    getData: function (data) {

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function () {
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, function (event) {
            // tool.showMessageBox("KEY:" + event.keyCode);
            if (this.tableLayer.active) {
                this.tableLayer.getComponent('KeyControl').onKeyPressed(event.keyCode);
            } else {
                this.getComponent('KeyControl').onKeyPressed(event.keyCode);
            }
        }, this);
        this.tableLayer.active = false;
    },



    start: function () {
        cc.windowManager.dismissWindowByName('loadingwin');
        this.init();

 
        // var ShaderUtils = require("ShaderUtils");
        // ShaderUtils.setShader(this.btnShop.getComponent(cc.Sprite), "gray"); 
        // var scene = cc.director.getScene();
        // var name = scene.name;



        // {"config":{"turn":8,"birdtype":0,"gametype":0,"hutype":0,"isPiao":false,"isRandom":false,"scoretype":28,"playnums":2},"ticket":"da1a3da918eef8117d43570db30bd7485099"}
    },


    onKyeBack: function () {
        cc.game.end();
    },

    onViewClick: function (view, data) {
        switch (data) {
            case 'game_csmj':

            case 'btn_hzmj':
                // cc.windowManager.showWindowByNameWithDate('enterwin', '812423');
                // break;
            case 'game_zzmj':
                {

                }
                // cc.windowManager.showWindowByNameWithDate('enterwin', 'enter');
                // break;
            case 'game_pdk':
                {
                    this.tableLayer.getComponent('TablesLayer').show(data);
                    // this.tableLayer
                }
                break;
            case 'shop':
                {
                    // tool.showMessageBoxWithCancel('暂未开放');
                    cc.game.end();
                }
                break;
        }
        // cc.windowManager.showMessageBox('测试一下好不好用啊！')
    }

    // update (dt) {},
});